package com.ximu.test.servlet;

import java.io.IOException;
import java.util.Random;
import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * 将servlet的计算结果传递到jsp页面
 * @author XIMU
 *
 */
public class ServletJsp extends HttpServlet {
	
	public void doGet(HttpServletRequest request,HttpServletResponse response)
			throws ServletException,IOException{
		Random random = new Random();
		int i = random.nextInt(100000);
		Cookie[] cookies = request.getCookies();
		if(cookies!=null)for(Cookie cookie:cookies){
			System.out.println(cookie.getName()+cookie.getValue());
		}
		HttpSession session = request.getSession();
		session.getId();
		session.setAttribute("test", "uuiuiuiui");
		request.setAttribute("servletI",i);
		request.getRequestDispatcher("/jsp/getdata.jsp").forward(request, response);
	}
	
	public void doPost(HttpServletRequest request,HttpServletResponse response)
			throws ServletException,IOException{
		doGet(request,response);
	}
}
